In all of the examples you will see references to Image Descriptors. The Image Descriptor is the data structure Victor uses to hold information about the image and the palette. The address of the Image Descriptor is an argument to every function call. Your application can handle any number of images at the same time.
Here is some sample code using Victor to load, sharpen, and display a grayscale 640 x 480 8-bit TIFF image. To allocate the image buffer and load the image . . .
imgdes image; /* Image descriptor */ int width = 640, length = 480; int bitsperpixel = 8; /* Bits per pixel */ allocimage(&image, width, length, bitsperpixel); loadtif("SPIDER.TIF", &image);If the image size and type are unknown we can use the tiffinfo function to gain the necessary information.
imgdes image; /* Image descriptor */ TiffData tdata; /* TIFF information */ int width, length; int bitsperpixel; tiffinfo("SPIDER.TIF"), &tdata); width = tdata.width; length = tdata.length; bitsperpixel = tdata.vbitcount; allocimage(&image, width, length, bitsperpixel); loadtif("SPIDER.TIF", &image);The allocimage function allocates space in global memory for the the image as a Device Independent Bitmap (DIB) with header, palette, and image data.
Next, apply image processing to enhance the grayscale image when displayed. To gently sharpen and balance the contrast of the image . . .
sharpengentle(&image, &image); histoequalize(&image, &image);To display the image in a window we use the following code.
HDC hDC; PAINTSTRUCT ps; HPALETTE hpal; . . . case WM_PAINT: hDC = BeginPaint(hWnd, &ps); viewimage(hWnd, hDC,&hpal,0,0,&image); EndPaint(hWnd,&ps);The viewimage function displays the image, sets, and realizes the colorpalette.
To release the memory before exiting the program . . .
freeimage(&image);
' Image descriptor Victor uses to hold information about the image Type imgdes ibuff As Long stx As Integer sty As Integer endx As Integer endy As Integer buffwidth As Integer palette As Long colors As Integer imgtype As Integer bmh As Long End Type Declare Function allocimage Lib "VIC.DLL" (image As imgdes, ByVal wid As Integer, ByVal leng As Integer, ByVal BPPixel As Integer) As Integer Declare Function bmpinfo Lib "VIC.DLL" (ByVal Fname As String, bdat As BITMAPINFOHEADER) As Integer Declare Sub freeimage Lib "VIC.DLL" (image As imgdes) Declare Function loadbmp Lib "VIC.DLL" (ByVal Fname As String, image As imgdes) As Integer Declare Function viewimage Lib "VIC.DLL" (ByVal hWnd As Integer, ByVal hDC As Integer, hpal As Integer, ByVal pos As Integer, ByVal ypos As Integer, image As imgdes) As IntegerDefine the image descriptor and file name variables.
'Global variables Global Fname As String Global vimage As imgdesThen add the Victor bmpinfo, allocimage, and loadbmp functions to the File Open Dialog box.
Sub IDM_OPEN_Click (Index As Integer) ' File Open Dialog box to load a BMP file Dim width As Integer Dim length As Integer Dim bitsperpixel As Integer Dim rcode As Integer Dim bmpdata As BITMAPINFOHEADER Cancel = False OpenDlg.Show 1 'Modal dialog box to get filename If Cancel = False Then ' Get information about the file to load rcode = bmpinfo(Fname, bmpdata) width = bmpdata.biWidth; length = bmpdata.biHeight; bitsperpixel = bmpdata.biBitcount ' Allocate new buffer to hold image rcode = allocimage(vimage, width, length, bitsperpixel) rcode = loadbmp(Fname, vimage) backcolor = &HFFFFFF ' Erase previous image form_paint ' Repaint the screen to display image ' Handle any errors If rcode <> NO_ERROR Then error_handler rcode, Fname End If End If End SubAnd the viewimage function is added to the Form Paint subroutine.
Sub form_paint () Dim hpal As Integer, rcode As Integer rcode = viewimage(hWnd, hDC, hpal, 0, 0, vimage) End Sub
Here is some sample code using Victor for Dos to load, display, and save a 640 x 480 8-bit palette color image. To allocate space for an image . . .
imgdes image; /* image descriptor */ int width = 640, length = 480; vmallocimage(&image, width, length, 8, EM_XM_CM_FM_);The vmallocimage function allocates space for the image and palette data. The constant EM_XM_CM_FM_ sets the strategy for the allocation. In this example vmallocimage seeks space for the buffer first in expanded, then extended, then conventional, and finally in virtual memory.
loadpcx("SPIDER.PCX", &image);The loadpcx function loads the image with its color palette. After the image is loaded, it is ready for processing, display, or saving to another file. To display the image on a Super VGA 640 x 480 256-color display adapter . . .
int viewmode = V640x480x256; /* Defined constant */ setvideomode(videomode); viewimageinit(viewmode, &image); /* Display image in the upper left corner of the screen */ viewimage(0, 0, &image);The viewimageinit function sets the display colors and initializes variables for the viewimage function. The viewimage function displays the image where requested without disturbing the rest of the screen.
Now that we have displayed the image, let's save it as a GIF file.
savegif("SPIDER.GIF", &image);To release the memory before exiting the program . . .
freeimage(&image);